package com.example.userservice.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.userservice.entity.user_account;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface UserMapper extends BaseMapper<user_account> {
    
    /**
     * 查询所有非管理员用户（role_id != 3）
     * @return 用户列表，包含用户信息和角色信息
     */
    @Select("SELECT ua.id, ua.username, ua.email, ua.status, ua.created_at as createTime, ur.role_id as roleId " +
            "FROM user_account ua " +
            "LEFT JOIN user_role ur ON ua.id = ur.user_id " +
            "WHERE ur.role_id != 1 OR ur.role_id IS NULL " +
            "ORDER BY ua.created_at DESC")
    List<Map<String, Object>> getNonAdminUsers();
}
